<?php
namespace app\admin\controller;

use app\core\Incontroller;
use KS\HTTP\HTTP;
use think\Request;
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

class Api extends Incontroller
{
    public function _empty($name){
        return ['err'=>1,'msg'=>'对不起，你没有此权限！'];
    }

    public function getQiniuUploadToken(){  //七牛云上传token获取
        vendor('qiniu/php-sdk/autoload.php');
        $qiniu = config('qiniu');
        $auth = new Auth($qiniu['accessKey'],$qiniu['secretKey']);
        $token = $auth->uploadToken($qiniu['bucket']); //七牛云上传凭证
        error(0,'获取成功',$token);
        exit;
    }

    public function delQiniuRes(){  //七牛云资源删除
        vendor('qiniu/php-sdk/autoload.php');
        $qiniu = config('qiniu');
        $auth = new Auth($qiniu['accessKey'],$qiniu['secretKey']);
        $key = str_replace($qiniu['domain'],'',urldecode($_GET['url']));
        $bucketMgr = new BucketManager($auth);
        $err = $bucketMgr->delete($qiniu['bucket'], $key);
        error(0,'删除成功');
        exit;
    }

}